package luj.tool.jnproxyan.proxy.stats.history.add;

import luj.tool.jnproxyan.proxy.stats.history.ConnectHistoryDat;
import luj.tool.jnproxyan.proxy.stats.history.HistoryItem;

import static com.google.common.base.Preconditions.checkNotNull;

public class ConnectResultUpdater {

  public ConnectResultUpdater(ConnectHistoryDat historyDat, Long requestId, HistoryItem.Result result) {
    _historyDat = historyDat;
    _requestId = requestId;
    _result = result;
  }

  public void update() {
    HistoryItem item = _historyDat.history().get(_requestId);
    checkNotNull(item, "不存在的连接请求：%s", _requestId);

    item.connectResult().set(_result.name());
  }

  private final ConnectHistoryDat _historyDat;
  private final Long _requestId;

  private final HistoryItem.Result _result;
}
